package com.kede.app.rest;

import com.kede.annotation.Log;
import com.kede.app.domain.ZhiAction;
import com.kede.app.service.ZhiActionService;
import com.kede.app.service.dto.ZhiActionQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Pr.li
* @date 2023-07-02
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "zhiAction管理")
@RequestMapping("/api/zhiAction")
public class ZhiActionController {

    private final ZhiActionService zhiActionService;

    /**
     * 导出数据
     **/
    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('zhiAction:list')")
    public void exportZhiAction(HttpServletResponse response, ZhiActionQueryCriteria criteria) throws IOException {
        zhiActionService.download(zhiActionService.queryAll(criteria), response);
    }

    /**
    * 查询zhiAction
    **/
    @GetMapping
    @Log("查询zhiAction")
    @ApiOperation("查询zhiAction")
    @PreAuthorize("@el.check('zhiAction:list')")
    public ResponseEntity<Object> queryZhiAction(ZhiActionQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(zhiActionService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    /**
    * 新增zhiAction
    **/
    @PostMapping
    @Log("新增zhiAction")
    @ApiOperation("新增zhiAction")
    @PreAuthorize("@el.check('zhiAction:add')")
    public ResponseEntity<Object> createZhiAction(@Validated @RequestBody ZhiAction resources){
        return new ResponseEntity<>(zhiActionService.create(resources),HttpStatus.CREATED);
    }


    /**
    * 修改zhiAction
    **/
    @PutMapping
    @Log("修改zhiAction")
    @ApiOperation("修改zhiAction")
    @PreAuthorize("@el.check('zhiAction:edit')")
    public ResponseEntity<Object> updateZhiAction(@Validated @RequestBody ZhiAction resources){
        zhiActionService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


    /**
    * 删除zhiAction
    **/
    @DeleteMapping
    @Log("删除zhiAction")
    @ApiOperation("删除zhiAction")
    @PreAuthorize("@el.check('zhiAction:del')")
    public ResponseEntity<Object> deleteZhiAction(@RequestBody Integer[] ids) {
        zhiActionService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}